//
//  ACELoginNavView.m
//  ACE
//
//  Created by zhangtao on 2018/8/7.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ACELoginNavView.h"

@implementation ACELoginNavView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        _backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 10, frame.size.height-40)];
        [_backBtn setBackgroundImage:[UIImage imageNamed:@"greenBack"] forState:UIControlStateNormal];
        [self addSubview:_backBtn];
        
        
        CGFloat W = 60;
        UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(frame.size.width/2-W, 0, W*2, frame.size.height)];
        middleView.backgroundColor = [UIColor clearColor];
        [self addSubview:middleView];
        
        _loginBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, W, frame.size.height)];
        [middleView addSubview:_loginBtn];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_loginBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
        [_loginBtn setTag:0];
        [_loginBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        
        _registBtn = [[UIButton alloc]initWithFrame:CGRectMake(W, 0, W, frame.size.height)];
        [middleView addSubview:_registBtn];
        [_registBtn setTitle:@"注册" forState:UIControlStateNormal];
        [_registBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        _registBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_registBtn setTag:1];
        [_registBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        
        _markLab = [[UILabel alloc]initWithFrame:CGRectMake(0, frame.size.height-10, W, 2)];
        _markLab.backgroundColor = RGB(23, 204, 81, 1);
        [middleView addSubview:_markLab];

        
    }
    return self;
}


-(void)click:(UIButton *)btn{
    if (self.loginOrRegistChangeCallBack) {
        self.loginOrRegistChangeCallBack(btn.tag);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        self.markLab.frame = CGRectMake(CGRectGetMinX(btn.frame), self.markLab.frame.origin.y, self.markLab.frame.size.width, 2);
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
        if (btn.tag == 0) {
            [self.registBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            self.registBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        }else{
            [self.loginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            self.loginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        }
    });
   
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
